import java.util.ArrayList;

/**
 * This class creates everything that a player needs to know for the game of 
 * 24/7. Some of the things that this class needs to function is access to the
 * classes of the Board and the DrawPile since this class uses them extensively
 * in the makeMove and drawTile methods of this class. Apart from that this 
 * class is a stand-alone class that manages each player.
 * 
 * @author Alex Gaskill
 * @version 3.0
 * @see Board, TileSet
 */
public class Player
{

        /**
         * This sets up the player class with all the things that a player needs to
         * know.
         */
        public Player()
        {
                _playerScore = 0;
                _tilesPlayerOwns =  new ArrayList<Integer>(5);
        }
        
        /**
         * this method returns the players score as an integer.
         * @return playerScore - the score that the player has earned for the 
         * duration of the game.
         */
        public int getScore()
        {
                return _playerScore;
        }
        
        /**
         * this method sets and adds the score to the players score.
         * @param score - is the score that they earned for the one turn.
         */
        public void setScore(int score)
        {
                _playerScore += score;
        }
        

        public void drawTile(int tile)
        {
            int zero = 0;
  
            int count = 0;
            boolean changed = false;

            while(count < _tilesPlayerOwns.size() && !changed)
            {
                if(zero == _tilesPlayerOwns.get(count))
                {
                    _tilesPlayerOwns.set(count, tile);
                    changed = true;
                }
                count++;
            }
        }
        
        /**
        * places a tile in to the players hand
        * @param tile - the tile that the player will receive in to its hand
        */
        public void setHand(int tile)
        {
            _tilesPlayerOwns.add(tile);
        }
        
        /**
         * this return the hand for the player.
         * @return hand - return the players current hand.
         */
        public ArrayList<Integer> getHand()
        {
        	return _tilesPlayerOwns;
        }
        
		/**
		 * this method checks to see if the hand can be added to.
		 * @return true if the hand size is less then 5 and false if the hand 
		 * equal to 5 and it should never be greater then 5.
		 */
        public boolean checkHand()
        {
        	return _tilesPlayerOwns.size() < 5;
        }

        public void setHasMoved(boolean move)
        {
            _hasMoved = move;
        }

        public boolean getHasMoved()
        {
            return _hasMoved;
        }

        public void removeTile(int tile)
        {
            Integer temp = new Integer(tile);
            Integer zero = new Integer(0);
            int count = 0;
            boolean changed = false;

            while(count < _tilesPlayerOwns.size() && !changed)
            {
                if(tile == _tilesPlayerOwns.get(count))
                {
                    _tilesPlayerOwns.set(count, zero);
                    changed = true;
                }
                count++;
            }
        }
        
		 // Class attributes
		 private int _playerScore;
		 private ArrayList<Integer> _tilesPlayerOwns;
                 private boolean _hasMoved;
}
